
 var isMobile = {  
		Android: function() {  
			return navigator.userAgent.match(/Android/i) ? true : false;  
		},  
		BlackBerry: function() {  
			return navigator.userAgent.match(/BlackBerry/i) ? true : false;  
		},  
		iOS: function() {  
			return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;  
		},  
		Windows: function() {  
			return navigator.userAgent.match(/IEMobile/i) ? true : false;  
		},  
		any: function() {  
			return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());  
		}  
	};  
	var evtFut;
    if( isMobile.any() )   
    {  
        evtFut = "touchend";
    }else{
		evtFut = "click";
	}  

(function() {
     "use strict";

    // custom scrollbar
   $("html").niceScroll({styler:"fb",cursorcolor:"#65cea7", cursorwidth: '6', cursorborderradius: '0px', background: '#424f63', spacebarenabled:false, cursorborder: '0',  zindex: '1000'});
    $(".left-side").niceScroll({styler:"fb",cursorcolor:"#65cea7", cursorwidth: '3', cursorborderradius: '0px', background: '#424f63', spacebarenabled:false, cursorborder: '0'});
    $(".left-side").getNiceScroll();
    if ($('body').hasClass('left-side-collapsed')) {
        $(".left-side").getNiceScroll().hide();
    }
	
	//如果浏览器宽度小于1024则隐藏左侧菜单
	if ($(document).width()<=1024){
		  $('body').addClass('left-side-collapsed');
		  setTimeout(function(){
			  	$('.custom-nav').children("li").children('ul').attr('style','');
			  },500);
		  $('a.toggle-btn').addClass('menu-collapsed');	
	}
	$(window).resize(function(){
		if ($(document).width()<=1024){
		  $('body').addClass('left-side-collapsed');
		  setTimeout(function(){
				$('.custom-nav').children("li").children('ul').attr('style','');
			  },500);
		  $('a.toggle-btn').addClass('menu-collapsed');	
		}
	})
	
 
	
		//菜单点击
    $(document).on(evtFut,".sub-menu-list>li>a",function(ev){
    	$('.main-content').css("height","auto");
		if ($(this).hasClass("active")){
			$(this).removeClass("active");
			$(this).siblings("ul").hide();	 
		}else{
			$(this).parent("li").siblings().children("a").removeClass("active");
			$(this).parent("li").parent("ul").children("li").children("ul.sub-menu-list").hide();
			$(this).parent("li").parent("ul").children("li").children("a.open_sub_menu").removeClass("active");
			$(this).parents(".menu-list").siblings(".menu-list").children("ul").find(".sub-menu-list").hide();
			$(this).addClass("active");
			$(this).siblings("ul").slideDown();		 
		}	
		
		 if( isMobile.any() )   
		    {  
			 $(this).click();
		    } 

	});
	 
	// Toggle Left Menu
	$(document).on(evtFut, '.menu-list > a', function() {
		var parent = $(this).parent();
		var sub = parent.find('> ul');
		if (!$('body').hasClass('left-side-collapsed')) {
			if (sub.is(':visible')) {
				sub.slideUp(200, function() {
					parent.removeClass('nav-active');
					parent.removeClass('nav-hover');
					$('.main-content').css({height : ''});
					mainContentHeightAdjust();
				});
			} else {
				visibleSubMenuClose();
				parent.addClass('nav-active');
				sub.slideDown(200, function() {
					//mainContentHeightAdjust();
				});
			}
		}else{
			if (sub.is(':visible')) {
				$(".menu-list").removeClass("nav-active").removeClass("nav-hover");
				sub.hide();
 			}else{
				$(".sub-menu-list").hide();
				$(".menu-list").removeClass("nav-active").removeClass("nav-hover"); 
				parent.addClass("nav-hover").addClass("nav-active");
				sub.show();

			}
		}
		// return false;
	});
   
   
  
   

   function visibleSubMenuClose() {
      $('.menu-list').each(function() {
         var t = $(this);
         if(t.hasClass('nav-active')) {
				t.find('> ul').slideUp(200, function(){
					t.removeClass('nav-active');	
				});
         }
      });
   }

   function mainContentHeightAdjust() {
      // Adjust main content height
	   $('.main-content').css("height","auto");
       var docHeight = $(document).height();
       if(docHeight > $('.main-content').height()){$('.main-content').height(docHeight);} 
	   
   }

   //  class add mouse hover
/*    $(document).on('mouseover','.custom-nav > li',function(){
	   $(this).addClass('nav-hover');
   });
   $(document).on('mouseout','.custom-nav > li',function(){
	   $(this).removeClass('nav-hover');
   }); */
  
     // Menu Toggle
	 $(document).on(evtFut,".toggle-btn",function(){
	  $(".left-side").getNiceScroll().hide();
	  
	  if ($('body').hasClass('left-side-collapsed')) {
			$(".left-side").getNiceScroll().hide();
	  }
	  
	  var body = $('body');
	  if(!body.hasClass('left-side-collapsed')) {
			  body.addClass('left-side-collapsed');
			  $('.custom-nav>li>ul.sub-menu-list').attr('style','');
			  $('.custom-nav>li>ul.sub-menu-list').attr('style','');
			  $(this).addClass('menu-collapsed');     
	  }else{
			  body.removeClass('left-side-collapsed chat-view');
			  $('.custom-nav li.active ul').css({display: 'block'});
			  $(this).removeClass('menu-collapsed');
			  $(".custom-nav .nav-active").children("ul.sub-menu-list").show();
	  }
	  mainContentHeightAdjust();  
   });
   
   searchform_reposition();

   $(window).resize(function(){
      if($('body').css('position') == 'relative') {
         $('body').removeClass('left-side-collapsed');
      } else {
         $('body').css({left: '', marginRight: ''});
      }
      searchform_reposition();
   });

   function searchform_reposition() {
      if($('.searchform').css('position') == 'relative') {
         $('.searchform').insertBefore('.left-side-inner .logged-user');
      } else {
         $('.searchform').insertBefore('.menu-right');
      }
   }

	
	
    // panel collapsible
	$(document).on(evtFut,".panel .tools a.fa",function(){
        var el = $(this).parents(".panel").children(".panel-body");
        //搜索条件显示控制
        if ($(this).hasClass("form_display")){
        	 if ($(this).hasClass("fa-chevron-down")) {
                 $(this).removeClass("fa-chevron-down").addClass("fa-chevron-up");
                 el.addClass("form_hide");
             } else {
                 $(this).removeClass("fa-chevron-up").addClass("fa-chevron-down");
                 el.removeClass("form_hide");
             } 	
        }
        else{
        	  if ($(this).hasClass("fa-chevron-down")) {
                  $(this).removeClass("fa-chevron-down").addClass("fa-chevron-up");
                  el.slideUp(200);   
              } else {
                  $(this).removeClass("fa-chevron-up").addClass("fa-chevron-down");
                  el.slideDown(200);    
              }	
        }   
    });

	$(document).on(evtFut,".todo-check label",function(){
        $(this).parents('li').children('.todo-title').toggleClass('line-through');
    });

    $(document).on(evtFut, '.todo-remove', function () {
        $(this).closest("li").remove();
        return false;
    });

    $("#sortable-todo").sortable();


    // panel close
	$(document).on(evtFut,".panel .tools .fa-times",function(){
        $(this).parents(".panel").parent().remove();
    });



    // tool tips

    $('.tooltips').tooltip();

    // popovers

    $('.popovers').popover();

	
	
})(jQuery);






//隐藏显示侧边栏
$(document).on(evtFut, ".menu-right a.hide_menu", function(e) {
	 if ($("body").hasClass("left-side-collapsed")){
		$("body").removeClass("left-side-collapsed");
		$(".logo i").addClass("hidden");
		$(".open_sub_menu").removeClass("active");
		$(".left-side").getNiceScroll().resize();
	 }else{
		$("body").addClass("left-side-collapsed");
		$(".logo i").removeClass("hidden");
		$(".open_sub_menu").removeClass("active");
		$(".left-side").getNiceScroll().resize();
	 }
	 $(".left-side-collapsed .custom-nav li.nav-active").removeClass("nav-active").removeClass("nav-hover");
	 $(".sub-menu-list").hide();
})
$(document).on(evtFut, "i.fa-indent", function(e) {
	if ($("body").hasClass("left-side-collapsed")){
	   $("body").removeClass("left-side-collapsed");
	   $(".logo i").addClass("hidden");
	}else{
	   $("body").addClass("left-side-collapsed");
	   $(".logo i").removeClass("hidden");
	}	
})


//------------------------------页面表格查询js------------------------------
var table_th=new Array();



function ReloadTableTh(){
	table_th = [];
	var countUndefined=0;
	$(".table_store thead th").each(function(i, n) {
		var obj=new Object();
		obj.name=$(n).attr("column");
		if(obj.name==undefined){
			countUndefined++;
			return true;
		}
		obj.id=i-countUndefined;
		obj.th_name=delHtmlTag($(n).text());
		obj.qtype=$(n).attr("qtype");
		obj.option="";
		obj.is_show=true;
		obj.order_id=i-countUndefined;
		table_th.push(obj);
	});
}

function loadFlag(id,$scope){
	ReloadTableTh();
	if (id != undefined) {
		// 加载查询参数
		$.ajax({
			type : "post",
			url : "entity/getFlag",
			cache : false,
			data:{id:id},
			async : false,
			dataType : "json",
			success : function(data) {
				if(data){
					var datas = JSON.parse(data.params);
					if(datas.params.length>0){
						var params = JSON.parse(datas.params);
						$scope.selected= {};
						for(var k in params){
							$("input[name='"+k+"']").val(params[k]);
							if($("select[name='"+k+"']").size()>0){
								$scope.selected[k]=params[k];
							}
						}
					}
					var search_opt = JSON.parse(datas.search_opt);
					if(search_opt.length>0){ 
						for(var i=0,j=search_opt.length;i<j;i++){
							table_th[search_opt[i].li_id].option=search_opt[i].option;
							$(".option_check_list").append(' <span class="btn btn-info btn-xs active" li_id="'+ search_opt[i].li_id+'"  data-toggle="popover" title="'+search_opt[i].title+'" data-content="'+search_opt[i].content+'">'+search_opt[i].title+' <i class="fa fa-times"></i></span>');
						}
						$(".option_check_list").append(' <button class="btn btn-danger btn-xs" id="remove_all_span"><i class="fa fa-times"></i> 清除筛选</button>');
						$('[data-toggle="popover"]').popover({"trigger":"hover","placement":"bottom"});
					}
					$scope.flag  = true;
					$scope.menuName=data.flag;
				}
			}
			
		});
	}
}

//保存筛选条件到li上和table_th数组内
function save_option_val(){

	var li_id=$("#option_edit").attr("li_id");
	var select_1=$(".select_val_1").val();
	var select_2=$(".select_val_2").val();
	var input_1=$.trim($(".select_val_1_text").val());
	var input_2=$.trim($(".select_val_2_text").val());
	var radio_1=$("input[name='optionsRadios']:checked").val();
	var check_result={"select_1":"","input_1":"","radio_1":"","select_2":"","input_2":""};

		 check_result.select_1=select_1;
		 check_result.input_1=input_1;
		 check_result.radio_1=radio_1;
		 check_result.select_2=select_2;
		 check_result.input_2=input_2;
		 check_result.qtype=$("#option_edit").attr("qtype");
	if ((select_1!="in" &&  select_1!="nn" && input_1!="") || (select_2!="in" &&  select_2!="nn" && input_2!="") || select_1=="in" || select_1=="nn" || select_2=="in" || select_2=="nn"){
			$("li[value='"+li_id+"'] input:hidden").val(JSON.stringify(check_result)); 
			table_th[li_id].option=JSON.stringify(check_result);
		}else{
			$("li[value='"+li_id+"']").attr("option_val","");
			table_th[li_id].option="";
	}
	check_li_selected();
}


//检测筛选条件是否有效，并还原筛选条件选框
function check_li_selected(){
	$(".select_li li").each(function(i,n) {
	    if ($.trim($(n).children("input").val())==""){
			$(n).removeClass("selected");	
		}else{
			$(n).addClass("selected");
		}
  });
}

//读取li上的条件筛选值并赋值
function set_option_val(str){
	obj=$.parseJSON(str); 
	$(".select_val_1 option[value='"+obj.select_1+"']").prop("selected",true);
	$(".select_val_2 option[value='"+obj.select_2+"']").prop("selected",true);
	$(".select_val_1_text").val(obj.input_1);
	$(".select_val_2_text").val(obj.input_2);
	$("input[name='optionsRadios'][value='"+obj.radio_1+"']").prop('checked',true);
}
//转条件名称
function select_option_name(str){
	switch (str)
	   {
	   case "lk":
		 str="相似";
		 break;
	   case "nk":
		str="不相似";
		 break;
	   case "eq":
		str="等于";
		 break;
	   case "ne":
		str="不等于";
		 break;
	   case "lt":
		str="小于";
		 break;
	   case "le":
		str="小于等于";
		 break;
	   case "gt":
		str="大于";
		 break;
	   case "ge":
		str="大于等于";
		 break;
	   case "in":
		str="为空";
		 break;
	    case "nn":
		str="不为空";
		 break;
		 case "and":
		str="并且";
		 break;
		 case "or":
		str="或者";
		 break;
	}
	return str;
}
//筛选条件转为中文
function option_to_str(option){
	option=$.parseJSON(option);
	var select_1=option.select_1;
	var select_2=option.select_2;
	var input_1=option.input_1;
	var input_2=option.input_2;
	var radio_1=option.radio_1;
	var str="";
	var str2="";
	//{"select_1":"nk","input_1":"12","radio_1":"or","select_2":"eq","input_2":"23"}
	//if ((select_1!="in" &&  select_1!="nn" && input_1!="") || (select_2!="in" &&  select_2!="nn" && input_2!="") || select_1=="in" || select_1=="nn" || select_2=="in" || select_2=="nn"){
	if (select_1=="in" || select_1=="nn"){
		str= select_option_name(select_1);
	}else if( input_1!=""){
		str=select_option_name(select_1)+input_1;
	}
	
	if (select_2=="in" || select_2=="nn"){
		str2=select_option_name(select_2);
	}else if( input_2!=""){
		str2=select_option_name(select_2)+input_2;
	}
	
	if(str!="" && str2!=""){
		return str+select_option_name(radio_1)+str2;
	} else{
		return str+str2;
	}
}

//js去掉所有html标记的函数： 
function delHtmlTag(str){
	return str.replace(/<[^>]+>/g,"");//去掉所有的html标记
}
//select转为ul下拉 
function reset_select_list(){	
		var obj=$(".select_list:visible").siblings(".select_edit");
		obj.siblings(".select_list:visible").css({top:(obj.offset().top+obj.outerHeight()-$(document).scrollTop())+"px",left:obj.offset().left+"px"});
		
}


	var isMobile = {  
		Android: function() {  
			return navigator.userAgent.match(/Android/i) ? true : false;  
		},  
		BlackBerry: function() {  
			return navigator.userAgent.match(/BlackBerry/i) ? true : false;  
		},  
		iOS: function() {  
			return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;  
		},  
		Windows: function() {  
			return navigator.userAgent.match(/IEMobile/i) ? true : false;  
		},  
		any: function() {  
			return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());  
		}  
	};  
 
	
function check_table_tr(){ 
	//如果表格行数大于20行则添加浮动表头
	if ($(".adv-table table.clone_table").size()<1 && $(".adv-table table.float_head tbody tr").size()>19){
		$(".adv-table table.float_head").clone().insertAfter($(".adv-table table.float_head"));
		$(".adv-table table.float_head:last").attr("id","").addClass("clone_table").children("tbody").remove();
		$(".adv-table table.clone_table thead tr th").attr("ng-show","");
	}
	$(".adv-table table.clone_table").css("width",($(".adv-table table.float_head:first").width()+2)+"px");
	$(".adv-table table.float_head:first thead tr th").each(function(i,n) {
        	$(".adv-table table.clone_table thead tr th").eq(i).css("width",$(n).width()+"px");
    });
	var height_val;
	
	if( isMobile.any() )  {
		//移动端
		$(window).scroll(function(){
			$(".clone_table").hide();
			$(".clone_table").stop( );
			if ($(document).scrollTop()+$(".header-section").height()>$(".adv-table").offset().top){
				height_val=($(document).scrollTop()+$(".header-section").height())-($(".adv-table").offset().top+6);
			}else{	
				height_val=0;
			}
			$(".clone_table").animate({top: height_val+"px"},200,function(){
				$(".clone_table").show();	
			});	
		})
	 
	}else{
		//pc
		$(window).scroll(function(){ 
			if ($(document).scrollTop()+$(".header-section").height()>$(".adv-table").offset().top){
				height_val=($(document).scrollTop()+$(".header-section").height())-($(".adv-table").offset().top+6);
				$(".clone_table").css("top", height_val+"px");	
			}else{
				$(".clone_table").css("top", "0px");	 
				 
			}
			 
		})
	}
	
}
 
 



$(document).ready(function(e) {
	
	
	
	//select转为ul下拉 
	$(document).on("focusin",".select_edit",function(){
		$(".select_list").hide();
		$(this).siblings(".select_list").show();
		$(this).siblings(".select_list").children("li").show();
		reset_select_list();
	})
	$(document).on("keyup",".select_edit",function(){
			var txt=$.trim($(this).val());
			var obj=$(this).siblings(".select_list");
			if (txt.length>0){
				obj.show();
				obj.children("li").hide();
				obj.children("li[val_code*='"+txt+"']").show();
				obj.children("li[val_name*='"+txt+"']").show();
			}else{
				obj.show();
				obj.children("li").show();
				obj.siblings(".select_value").val("");
			}
			reset_select_list();	
	})
	$(document).on(evtFut,".select_list li",function(){
			var obj=$(this).parent();
			obj.hide();
			obj.siblings(".select_edit").val($(this).attr("val_name"));
			obj.siblings(".select_value").val($(this).attr("val_code"));
	})
	//隐藏下拉列表
	$(document).on(evtFut,"body",function(e){
		if(!$(e.target).parent().hasClass("select_list") && !$(e.target).hasClass("select_edit")){
			$(".select_list").hide();
		}
	})
	
	$(document).on("scroll",function(){
		if ($(".select_list") && $(".select_list:visible").size()>0){
			reset_select_list();
		}
	})

	
	//select转为ul下拉 结束
	
	//筛选条件激活
	$(document).on(evtFut,".option_check_list span",function(e){
		 
		if ($(this).hasClass("active"))
		{
			$(this).attr("class","btn btn-default btn-xs");
		}
		else{
			$(this).attr("class","btn btn-info btn-xs active");
		}
	});
	//删除单个筛选条件
	$(document).on(evtFut,".option_check_list span i.fa-times",function(e){
		e.stopPropagation();
		var id=$(this).parent().attr("li_id");
		$("#table_th_list li[value='"+id+"']").removeClass("selected");
		$("#table_th_list li[value='"+id+"']").children("input").val("");
		$(this).parent("span").popover("destroy");
		$(this).parent("span").remove();
		table_th[id].option="";
		if ($(".option_check_list span").size()==0){
			$("#remove_all_span").remove();
			clearData();
		}
	});
	//删除所有筛选条件
	$(document).on(evtFut,"#remove_all_span",function(){
		$("#table_th_list li").removeClass("selected");
		$("#table_th_list li").children("input").val("");
		$(this).siblings("span").popover("destroy");
		$(this).siblings("span").remove();
		$(this).remove();
		$.each(table_th,function(i,n){
			n.option="";
		});
		clearData();
	});
	
	//搜索列检索
	$(document).on("keyup","#search_option_li",function(){
		if ($.trim($(this).val())!=""){
			$("#table_th_list li").hide();
			$("#table_th_list li:contains('"+$.trim($(this).val())+"')").show();
		}else{
			$("#table_th_list li").show();
		}
	});
	  
	/*
	$(document).on("show.bs.modal","#paramsSelect",function(){
		$("#table_th_list").html("");
		table_th=[];
		$("#table_show thead th").each(function(i, n) {
			var column = $(n).attr("data-column") ;
			if (column!=undefined&&column!='index_id'){
				table_th.push('{"id":"'+i+'","name":"'+$(n).attr("data-column")+'","th_name":"'+delHtmlTag($(n).text())+'","option":""}');
				$("#table_th_list").append('<li value="'+i+'" option_val="">'+$(n).text()+'</li>');	
			}
	    });
	});
	*/
	$(document).on("shown.bs.modal","#paramsSelect",function(){ 
		
		//生成筛选条件列表
		if($("#table_th_list").children().size()>0)
			return;
		$.each(table_th,function(i, n) {
			if(n.th_name=='序号'||n.th_name=='明细')
				return true;
			if (n.option!=""){ 
				$("#table_th_list").append('<li qtype="'+n.qtype+'" value="'+n.id+'" clas="selected" ><input type="hidden" value=""/>'+n.th_name+'</li>');
				$("#table_th_list li[value='"+n.id+"']").children("input").val(n.option);
			}else{
				$("#table_th_list").append('<li qtype="'+n.qtype+'" value="'+n.id+'" ><input type="hidden" value=""/>'+n.th_name+'</li>');
			}	
	   });
		check_li_selected();
	});
	
	//弹出框关闭时生成筛选条件
	$(document).on("hidden.bs.modal","#paramsSelect",function(e){
	 	
	});
	

	//筛选条件修改时生成触发保存值
	$(document).on("change","#option_edit input",function(){ 
			save_option_val();
	});
	$(document).on("change",".select_val_1,.select_val_2",function(){
			save_option_val();
	});
	
	//列筛选条件点击
	$(document).on(evtFut,"#table_th_list li",function(){
			$("#option_edit input").prop("disabled",false);
			$("#option_edit select").prop("disabled",false); 
			$("#option_edit h4").html($(this).text()).show();
			check_li_selected();
			$("#option_edit").attr("li_id",$(this).attr("value"));
			$(this).addClass("selected");
			var option_val=$.trim($(this).children("input").val());
			$("#option_edit input[type='text']").val("");
			
			var qtype = $(this).attr('qtype');
			if(qtype=='date'||qtype=='double'){
				$("select.select_val_2,select.select_val_1").children("option[value='lk']").remove();
				$("select.select_val_2,select.select_val_1").children("option[value='nk']").remove();
				$("select.select_val_2,select.select_val_1").children("option[value='eq']").remove();
				$("select.select_val_2,select.select_val_1").children("option[value='ne']").remove();
			}else{
				if($("select.select_val_2,select.select_val_1").children("option[value='lk']").size()==0){
					$("select.select_val_2,select.select_val_1").prepend("<option value='ne'>不等于</option>");
					$("select.select_val_2,select.select_val_1").prepend("<option value='eq'>等于</option>");
					$("select.select_val_2,select.select_val_1").prepend("<option value='nk'>不相似</option>");
					$("select.select_val_2,select.select_val_1").prepend("<option value='lk'>相似</option>");
					
				}
			}
			$("select.select_val_2").children("option:first").prop("selected",true);
			$("select.select_val_1").children("option:first").prop("selected",true);
		 	if (option_val!=""){ 
				set_option_val(option_val);
			} 
	})
	
	 $(document).on(evtFut,"body",function(e){	  
		if (!$(e.target).parents(".col_show_list").hasClass("col_show_list")){
			$(".col_show_list ul").hide();
		}	 
	 })
	
	
	
	
});

function joinParams(){
	$(".option_check_list").html("");
	var add_btn=false;
	$("#table_th_list li").each(function(i,n) {
      	var option=$(n).children("input").val();
			var name=$(n).text();
			var li_id=$(n).attr("value");
			if (option!=""){
				add_btn=true;
				$(".option_check_list").append(' <span class="btn btn-info btn-xs active" li_id="'+ li_id+'"  data-toggle="popover" title="'+name+'" data-content="'+option_to_str(option)+'">'+name+' <i class="fa fa-times"></i></span>');
				
			}
  });
	if (add_btn){$(".option_check_list").append(' <button class="btn btn-danger btn-xs" id="remove_all_span"><i class="fa fa-times"></i> 清除筛选</button>');}
	
	$('[data-toggle="popover"]').popover({"trigger":"hover","placement":"bottom"});
}

//清除查询条件时，清空表单数据或回复默认选项
function clearData(){
	$("#option_edit").find("h4").hide();
	$("#search_option_li").val("").keyup();
	$("#option_edit").find("select").each(function(){
		$(this).find("option:first").attr("selected", true);
	});
	$("#option_edit").find("input[type=text]").each(function(){
		$(this).val("");
	});
	$("#option_edit").find("input[type=radio]").each(function(){
		if($(this).val()=='and'){
			$(this).attr("checked", true);
		}
	});
}

$(function(){
	//原型方法添加
	Array.prototype.contains = function(val){
		for (var i = 0; i < this.length; i++) {
			if (this[i] == val) return true;
		}
		return false;
	};
	Array.prototype.indexOf = function(val) {
		for (var i = 0; i < this.length; i++) {
			if (this[i] == val) return i;
		}
		return -1;
	};
	Array.prototype.remove = function (val) {
	    var index = this.indexOf(val);  
	    if (index > -1) {  
	        this.splice(index, 1);  
	    }  
	};
});


 




function alertMsg(title,msg,func5){
	var box='<div class="modal in" id="alertConfirm" data-backdrop="false" aria-hidden="false">';
        box+='<div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h4 class="modal-title">'+title+'</h4>';
        box+='</div><div class="modal-body"><div class="row" style="padding:30px;"><div class="col-xs-8 col-xs-offset-2 text-center text-info"><h5 style="font-size:16px;">'+msg+'</h5></div>';
        box+='</div></div><div class="modal-footer text-center"><button class="btn btn-success" id="alertYes" type="button">确定</button></div></div></div></div>';     
		$('body').append(box)
		$('#alertConfirm').modal({keyboard: true,backdrop:'static'});
		$('#alertYes').click(function(){
			func5&&func5();
			$('#alertConfirm').modal('hide');
		}) 
		$('#alertConfirm').on('hidden.bs.modal', function () {
			$('#alertConfirm').remove();
		})
}


function showconfirm(msg,func1,func2){
	var box='<div class="modal in" id="showConfirm" data-backdrop="false" aria-hidden="false">';
        box+='<div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h4 class="modal-title">提示</h4>';
        box+='</div><div class="modal-body"><div class="row" style="padding:30px;"><div class="col-xs-12 text-center  text-danger"><h5 style="font-size:16px;">'+msg+'</h5></div>';
        box+='<div class="col-xs-12 text-center">';
        box+='</div></div></div><div class="modal-footer text-center"><button class="btn btn-success" id="confirmYes" type="button">确定</button><button class="btn btn-warning" id="confirmNo" type="button">取消</button></div></div></div></div>';     
		$('body').append(box)
		$('#showConfirm').modal({keyboard: true,backdrop:'static'});
		$('#confirmYes').click(function(){
			func1&&func1();
			$('#showConfirm').modal('hide');
		})
		$('#confirmNo').click(function(){
			func2&&func2();
			$('#showConfirm').modal('hide');
		})
		$('#showConfirm').on('hidden.bs.modal', function () {
			$('#showConfirm').remove();
		})
}


function showconfirm_input(title,msg,func3,func4){
	var box='<div class="modal in" id="showConfirm_input" post_val="false" data-backdrop="false" aria-hidden="false">';
        box+='<div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h4 class="modal-title">提示：'+title+'</h4>';
        box+='</div><div class="modal-body"><div class="row" style="padding:10px;"><div class="col-xs-6 col-xs-offset-3 text-info "><h5 style="font-size:16px;">'+msg+'</h5></div>';
        box+='<div class="col-xs-6 col-xs-offset-3 text-center"><input class="form-control" type="text" value="" name="prompt_val">';
        box+='</div><div class="col-xs-6 col-xs-offset-3 text-center text-danger error_msg" style="font-size:16px;padding-top:20px;"></div></div></div><div class="modal-footer text-center"><button class="btn btn-success" id="confirm_input_Yes" type="button">确定</button><button class="btn btn-warning" id="confirm_input_No" type="button">取消</button></div></div></div></div>';     
		$('body').append(box)
		$('#showConfirm_input').modal({keyboard: true,backdrop:'static'});
		$('#confirm_input_Yes').click(function(){
			func3&&func3();	  
		})
		
		$('#confirm_input_No').click(function(){
			func4&&func4();
			$('#showConfirm_input').modal('hide');
		})
		$('#showConfirm_input').on('hidden.bs.modal', function () {
			$('#showConfirm_input').remove();
		})
}

$(document).ready(function(e) {
	setTimeout(function(){
		$(".select2").css("width",$(".select2").parent("div").width()+"px");
	},1000)    
});

var ValidF = (function(window, document, $) {

	var v = {
		regs : {
			double : /^([-|\/])(\d{1,12})(\.\d{1,2})?$/,
			number : /^\d{1,8}$/,
			email : /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/,
			date : /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})$/,
			datetime : /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/,
			phone : /^1[3|4|5|7|8][0-9]{9}$/,
			idcard : /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)/,
			textlen : /^(.|\n){0,255}$/,
			text50 : /^(.|\n){0,50}$/,
			year : /^([2][0][0-9]{2})$/,
			month : /^(0?[1-9]|1[0-2])$/,
			day : /^((0?[1-9])|((1|2)[0-9])|30|31)$/,
			fixPhone : /^((0\d{2,3}-\d{7,8})|(1[35784]\d{9}))$/,
			businessLicence:/^([0-9ABCDEFGHJKLMNPQRTUWXY]{2})([0-9]{6})([0-9ABCDEFGHJKLMNPQRTUWXY]{9})([0-9Y])$/,
		}
	};
	v.initConfig = function() {
		v.config = {
			sel : ".input_params",
			msgDiv : "#reg_tip_box",
			id : ""
		};

	}
	v.valid = function(config) {
		v.initConfig();
		if (config)
			$.extend(v.config, config);
		if (v.config.sel)
			v.config.clazz = v.config.id + " " + v.config.sel;
		var flag = true;
		$(v.config.clazz).each(function() {
			var _this = $(this);
			var value = _this.val();
			var require = _this.attr('require');
			if (require != undefined&&!config.uncheck) {
				if (value == "" || value == null || value.indexOf("?")!=-1) {
					var msg = require;
					if (msg === '')
						msg = _this.attr('error');
					v.alert(msg);
					_this.focus();
					return flag = false;
				} else {
					var valid = _this.attr('valid');
					if (valid != undefined) {
						var reg = v.regs[_this.attr('valid')];
						if (!reg.test(value)) {
							v.alert(_this.attr('error'));
							_this.focus();
							return flag = false;
						}
					}
					var reg = _this.attr('reg');
					if (reg != undefined) {
						var reg = eval(_this.attr("reg"));
						if (!reg.test(value)) {
							v.alert(_this.attr('error'));
							_this.focus();
							return flag = false;
						}
					}
				}

			} else {
				if (value) {
					var valid = _this.attr('valid');
					if (valid != undefined) {
						var reg = v.regs[_this.attr('valid')];
						if (!reg.test(value)) {
							v.alert(_this.attr('error'));
							_this.focus();
							return flag = false;
						}
					}
					var reg = _this.attr('reg');
					if (reg != undefined) {
						var reg = eval(_this.attr("reg"));
						if (!reg.test(value)) {
							v.alert(_this.attr('error'));
							_this.focus();
							return flag = false;
						}
					}
				}
			}

		});
		if (flag)
			$(v.config.msgDiv).hide();
		return flag;
	};
	v.alert = function(msg) {
		if (v.config.alert == "box") {
			alertMsg("提示", msg);
			return;
		}
		if (v.timeout)
			clearTimeout(v.timeout);
		$(v.config.msgDiv + " .msg").text(msg);
		$(v.config.msgDiv).fadeIn();
		v.timeout = setTimeout(function() {
			$(v.config.msgDiv).fadeOut();
		}, 5000);
	}, v.alertMsg = function(clazz, msg) {
		if (v.timeout)
			clearTimeout(v.timeout);
		$(clazz + " .msg").text(msg);
		$(clazz).fadeIn();
		v.timeout = setTimeout(function() {
			$(clazz).fadeOut();
		}, 3000);
	}, v.hideMsg = function() {
		$(v.config.msgDiv).hide();
	}
	return v;
})(window, window.document, window.jQuery);
